package com.taozi.netty.socketio.use.classroomchat.controller.education;


import com.github.pagehelper.Page;
import com.taozi.netty.socketio.use.classroomchat.controller.PageInfo;
import com.taozi.netty.socketio.use.classroomchat.controller.ResultCode;
import com.taozi.netty.socketio.use.classroomchat.controller.ResultInfo;
import com.taozi.netty.socketio.use.classroomchat.entity.entity.education.Classroom;
import com.taozi.netty.socketio.use.classroomchat.service.education.IClassroomService;
import com.taozi.netty.socketio.use.classroomchat.entity.vo.education.ClassroomBean;
import com.taozi.netty.socketio.use.classroomchat.entity.vo.education.ClassroomVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 课堂信息
 *
 * @author mingtao
 */
@Controller
@RequestMapping("/classroom")
public class ClassroomController {

    @Autowired
    IClassroomService classroomService;

    /**
    * @description 添加课堂
    * @param classroomVo
    * @return com.sccddw.cpss.entity.bean.common.ResultInfo<Classroom>
    * @author mingtao
    **/
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ResponseBody
    public ResultInfo<Classroom> insert(@Valid @RequestBody ClassroomVo classroomVo) {
        ResultInfo resultInfo = new ResultInfo();
        if (classroomVo == null || StringUtils.isEmpty(classroomVo.getTitle())
                || classroomVo.getCourseId() ==null || classroomVo.getClassroomType() == null) {
            resultInfo.setResultCode(ResultCode.PARAM_IS_BLANK);
            return resultInfo;
        }

        Classroom classroom = new Classroom();
        //入库业务

        if(classroom != null){
            resultInfo.setData(classroom);
            resultInfo.setResultCode(ResultCode.SUCCESS);
        }else {
            resultInfo.setResultCode(ResultCode.DATA_ADD_ERROR);
        }
        return resultInfo;
    }

    /**
    * @description 分页查询
    * @param page
    * @param rows
    * @return com.sccddw.cpss.entity.bean.common.PageInfo<ClassroomBean>
    * @author mingtao
    **/
    @RequestMapping(value = "/pageFindList", method = RequestMethod.GET)
    @ResponseBody
    public PageInfo<ClassroomBean> pageFindList(@RequestParam(required = false, defaultValue = "0") Integer page, @RequestParam(required = false, defaultValue = "10") Integer rows) {

        PageInfo pageInfo = new PageInfo();

        ClassroomVo classroomVo = new ClassroomVo();
        classroomVo.setPage(page);
        classroomVo.setRows(rows);
        Page<ClassroomBean> classroomPage = classroomService.pageFindList(classroomVo);
        pageInfo.setTotal(classroomPage.getTotal());
        pageInfo.setRows(classroomPage.getResult());
        pageInfo.setResultCode(ResultCode.SUCCESS);
        return pageInfo;
    }







}
